package com.dataseek.iot.mysql.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.dataseek.iot.mysql.entity.Dict;
import com.dataseek.iot.mysql.mapper.DictMapper;
import com.dataseek.iot.mysql.service.IDictService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author cc
 * @since 2021-09-19
 */
@Service
public class DictServiceImpl extends ServiceImpl<DictMapper, Dict> implements IDictService {


    /**
     * 获取产品相关的字典
     * @param list
     * @return
     */
    public List<Dict> getAllByProductId(List list){
        QueryWrapper wrapper = new QueryWrapper();
        wrapper.in("dict_inner_id", list);
        return this.list(wrapper);
    }

    /**
     * 获取产品字典的code
     * @param list
     * @return
     */
    public List<String> getAllDictCodeByProductId(List list){
        List<Dict> dicts = getAllByProductId(list);
        List<String> names = new ArrayList<>();
        for(Dict d : dicts){
            names.add(d.getParamCode());
        }
        return names;
    }
}
